﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Obstacle : MonoBehaviour {

	public SpriteRenderer good = null;
	public SpriteRenderer broke = null;

	void Start()
	{
		good.enabled = true;
		broke.enabled = false;
	}

	public static Obstacle obs = null;
	void OnTriggerEnter2D(Collider2D collider)
	{
		if (collider.gameObject.name == "flag") {

			if (gameObject.tag == "firstGudian") {
			
				// guide
				gameUI.GetInstance().ShowGuide(true);
			}

			return;
		}

		if ( gameObject.name == "obstacle" )
			ObstacleBroke ();

		if (gameObject.name == "balled")
			obs = this;
	}

	void OnTriggerExit2D(Collider2D collider)
	{
		if (collider.gameObject.name == "flag") {
		
			// 检测是否已破
			if (gameObject.name == "obstacle" && good.enabled == true) {
				// 加一分
				SceneCreator.GetInstance().AddScore();

			}

			if (gameObject.tag == "lastGudian") {
			
				// finish
				SceneCreator.GetInstance().FinishGame();
			}
		}

		if (gameObject.name == "balled")
			obs = null;
	}
		



	public void ObstacleBroke()
	{
		good.enabled = false;
		broke.enabled = true;
	}




}
